package main

import "fmt"

//初始化链表结构
type Listnode struct {
	Val int
	Next *Listnode
}

func reversed(head *Listnode) *Listnode{
	var pre *Listnode = nil
	cur := head
	for cur != nil{
		temp := cur.Next
		cur.Next = pre
		pre = cur
		cur = temp
	}
	return pre

}

func main()  {
	l4 := Listnode{
		Val: 4,
		Next: nil,
	}
	l3 := Listnode{
		Val: 3,
		Next: &l4,
	}
	l2 := Listnode{
		Val: 2,
		Next: &l3,
	}
	l1 := Listnode{
		Val: 1,
		Next: &l2,
	}
	L := reversed(&l1)
	for L != nil{
		fmt.Printf("%d\t",L.Val)
		L = L.Next
	}
}

func reverse1(head * Listnode) *Listnode{
	var pre *Listnode = nil
	cur := head
	for cur != nil{
		tem := cur.Next
		cur.Next = pre
		cur = pre
		pre = tem
	}

}